package com.huitone.smspfm.core.filter;

import java.util.List;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

import com.huitone.smspfm.logger.ExtLogger;

import com.bin.common.utils.StringUtils;
import com.huitone.smspfm.core.constant.DealResult;
import com.huitone.smspfm.model.SmsEntityForMt;

/**   
* @Title IlligalUserFilterTask.java 
* @Package com.huitone.smspfm.core.task 
* @Description TODO(用一句话描述该文件做什么) 
* @author ybliang   
* @date 2017年6月17日 上午11:32:00 
* @version V1.0   
*/
public class IlligalUserFilterTask extends Thread {
	
	private ExtLogger logger = ExtLogger.create(IlligalUserFilterTask.class);
	
	private String moduleName = "非法用户过滤模块";
	
	//private byte[] moduleNameB = AppStaticConfigs.stringRedisSerializer.serialize(moduleName);
	
	private List<SmsEntityForMt> entities = null;
	
	private CyclicBarrier barrier = null;
	
	public IlligalUserFilterTask(List<SmsEntityForMt> entities, CyclicBarrier barrier) {
		this.entities = entities;
		this.barrier = barrier;
	}

	@Override
	public void run() {
		
		if (entities == null) return;
		
		long start = System.currentTimeMillis();
		
		for (SmsEntityForMt entity:entities) {
			
			if (!StringUtils.isPhNum(entity.getPhoneNumber())) {
				
				entity.setDealResultCodeMap(moduleName, DealResult.RESULT_6);
				entity.setInterceptedCode(DealResult.RESULT_6);
				entity.setInterceptedDesc(DealResult.RESULT_6_DESC);
				entity.setIntercepted(true);
				
				logger.debug("[序列号:用户号码][" + entity.getSerialno() + ":" + entity.getPhoneNumber() + "]被不合法号码检测过滤器捕获,处理流程结束。");
			
			} else {
				
				entity.setDealResultCodeMap(moduleName, DealResult.RESULT0);
			}
		}
		
		long end = System.currentTimeMillis();
		
		logger.debug("非法用户过滤执行完毕,共耗时:" + (end - start) + "毫秒");
		
		try {
			barrier.await();
		} catch (InterruptedException | BrokenBarrierException e) {
			e.printStackTrace();
		}
	}
}
